<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class Auth extends MX_Controller {
	
	function __construct() {
		$this->load->library ( 'session' );
		$this->load->model ( 'admin_model' );
		parent::__construct ();
	}
	
	public function index() {
		$this->load->view ( 'login' );
	}
	
	public function login() {
		//$this->load->view('welcome_message');
		$username = $this->input->post ( 'username' );
		$password = $this->input->post ( 'password' );
		$sessionKey = $this->input->post ( 'formKey' );
		$success = $this->admin_model->login ( $username, $password );
		
		if ($success) {
			echo 'Login Successfully';
			$this->admin_model->setData ( 'sessionKey', $sessionKey );
			$loggedSessionData = array ('admin' => $this->admin_model, 'formKey' => $sessionKey, 'logged_in' => TRUE );
			$this->session->set_userdata ( $loggedSessionData );
		} else {
			echo 'Login Failed';
		}
	}
}
